import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import router from '@/router'
import { RouteLocationNormalized } from 'vue-router'
import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false })

router.beforeEach(
  async(
    to: RouteLocationNormalized,
    from: RouteLocationNormalized,
    next: any
  ) => {
    // if(from.name === 'HealthReport' && to.name !== 'RiskAnalysis') {
    //   from.meta.keepAlive = false
    // }else {
    //   if(to.name === 'HealthReport') {
    //     to.meta.keepAlive = false
    //   }
    // }
    NProgress.start()
    document.title = getPageTitle(to.meta.title) // 设置页面title
    next()
    NProgress.done()
  }
)

router.afterEach(() => {
  NProgress.done()
})
